<template>
  <div>
    <div
      style="
        width: 100%;
        height: 340px;
        background-image: linear-gradient(#d0e8ff, #f5f5f5);
        position: absolute;
        z-index: -100;
      "></div>
    <div style="position: absolute; right: 10px; top: 5px; z-index: 1000">
      <common-back @clicked="handleClosePage"></common-back>
    </div>
    <div :key="keyForTimeline" style="padding-top: 10px">
      <div style="display: flex; width: 100%; justify-content: center; flex-direction: column; align-items: center">
        <div style="z-index: 2; text-align: center; color: #3387ff; font-size: 16px; font-weight: 600">沟通时间线</div>
        <div
          style="
            z-index: 1;
            width: 76px;
            height: 6px;
            background-image: linear-gradient(to right, #237eff, #d4e4fa);
            margin-top: -4px;
            border-radius: 8px;
          "></div>
      </div>
      <div style="width: 100%; display: flex; justify-content: center; align-items: center">
        <div
          style="
            padding: 12px 16px;
            margin: 12px 16px 12px 16px;
            background-color: rgba(255, 255, 255, 0.8);
            flex: 1;
            color: #666666;
            font-size: 14px;
            border-radius: 12px;
          ">
          <div v-for="(item, index) in lstRecord" :key="index" style="margin-bottom: 12px">
            <div style="display: flex; align-items: center; margin-bottom: 8px; font-size: 12px">
              <span style="color: #666666; margin-right: 6px">{{ item.createTime.replace('T', ' ') }}</span>
              <span
                :style="{
                  color: fltRecTypeColor(item.type),
                  'background-color': fltRecTypeBgColor(item.type),
                  padding: '2px 6px 0px 6px',
                  'border-radius': '4px',
                }">
                {{ fltRecType(item.type) }}
              </span>
              <span
                v-if="item.status === 0 && item.type === 0"
                style="
                  color: #999999;
                  background-color: #f5f5f5;
                  padding: 2px 6px 0px 6px;
                  border-radius: 4px;
                  margin-left: 6px;
                ">
                未成交
              </span>
              <span
                v-if="item.status === 1 && item.type === 0"
                style="
                  color: #ff7510;
                  background-color: #ffecde;
                  padding: 2px 6px 0px 6px;
                  border-radius: 4px;
                  margin-left: 6px;
                ">
                成交
              </span>
              <span
                v-if="item.type === RecordType.APPLY_ORDER.id"
                :style="{
                  color: item.status === 0 ? '#663399' : item.status === 1 ? '#009999' : '#FF3333',
                  margin: '0 0 0 5px',
                }">
                {{ item.status === 0 ? '开单' : item.status === 1 ? '跟进' : '关闭' }}
              </span>
            </div>
            <div v-if="item.type === RecordType.IMAGE.id" style="width: 100%; text-align: center">
              <img :src="calSourceUrl(item.url)" style="border: none; width: 200px" />
            </div>
            <div
              v-else-if="item.type === RecordType.AUDIO.id || (item.type === RecordType.APPLY_ORDER.id && item.url)"
              style="width: 100%; text-align: center">
              <audio :src="calSourceUrl(item.url)" controls></audio>
            </div>
            <div v-else>
              <div
                style="
                  padding: 4px 8px;
                  flex: 1;
                  color: #333333;
                  font-size: 14px;
                  border-radius: 4px;
                  background-color: #f5f5f5;
                "
                @click="popFaceTag(item)">
                <div
                  v-if="item.status === 1 && item.type === 0"
                  style="font-size: 12px; color: #999999; margin-bottom: 4px">
                  品项：{{ item.item }}
                </div>
                <div>
                  <span
                    v-if="item.type === 4 && item.status === 1"
                    style="
                      border-radius: 6px;
                      padding: 3px 8px;
                      background-color: #e5f0ff;
                      font-size: 12px;
                      color: #237eff;
                      margin-bottom: 4px;
                    ">
                    {{ item.item }}
                  </span>
                  <span
                    v-if="item.type === 4 && item.status === 2"
                    style="
                      border-radius: 6px;
                      padding: 3px 8px;
                      background-color: #fee9e9;
                      font-size: 12px;
                      color: #ff4d4d;
                      margin-bottom: 4px;
                    ">
                    {{ item.item }}
                  </span>
                </div>
                <div>
                  <span style="white-space: pre-wrap">{{ item.content }}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div style="height: 20px"></div>
    <van-tabbar style="z-index: 100; display: flex; align-items: center; justify-content: center; opacity: 1">
      <van-button
        round
        block
        type="info"
        plain
        style="z-index: 100; width: 40%; height: 40px; background-color: #e5f0ff; opacity: 1"
        @click="iniRecord">
        新增记录
      </van-button>
      <van-button
        v-if="consumerObj.coachOrderId > 0"
        round
        block
        type="warning"
        plain
        style="z-index: 100; width: 40%; height: 40px; background-color: #e5f0ff; opacity: 1"
        @click="goCloseOrder">
        关闭会诊
      </van-button>
    </van-tabbar>

    <van-popup
      v-model="popRecord"
      round
      position="bottom"
      :overlay="true"
      :lock-scroll="false"
      :style="{ height: '80%' }">
      <div style="display: flex; align-items: center; justify-content: center; font-size: larger; padding: 10px 10px">
        <van-radio-group v-model="recordCard.cur" direction="horizontal">
          <van-radio :name="1">普通</van-radio>
          <van-radio :name="2">图片</van-radio>
          <van-radio :name="3">音频</van-radio>
        </van-radio-group>
      </div>
      <!--普通事件-->
      <div v-if="recordCard.cur === recordCard.normal" class="add_record_normal">
        <div style="margin: 24px 24px 12px 24px">
          <van-field
            v-model="newConsult.content"
            rows="2"
            autosize
            type="textarea"
            show-word-limit
            :maxlength="newConsult.type == 7 ? 160 : 660"
            style="background-color: #f5f5f5; border-radius: 12px"
            :placeholder="newConsult.type == 7 ? '描述会诊需求' : '输入记录内容(成交时可以不用输入)'"></van-field>
        </div>
        <div style="color: #666666; font-size: 16px; margin: 0 0 12px 24px">记录类型</div>
        <div style="display: flex; align-items: center; justify-content: center; font-size: larger">
          <van-radio-group v-model="newConsult.type" direction="horizontal">
            <van-radio :name="3" style="margin-right: 50px">客情</van-radio>
            <van-radio :name="7" style="margin-right: 50px">会诊</van-radio>
            <van-radio :name="0">咨询</van-radio>
          </van-radio-group>
        </div>
        <div v-if="newConsult.type === 0" style="margin: 12px 24px">
          <div style="color: #666666; font-size: 16px; margin: 0 0 12px 0">是否成交</div>
          <div style="display: flex; align-items: center; justify-content: center; font-size: larger">
            <van-radio-group v-model="newConsult.status" direction="horizontal">
              <van-radio :name="0" style="margin-right: 34px">未成交</van-radio>
              <van-radio :name="1">成交</van-radio>
            </van-radio-group>
          </div>
        </div>
        <div v-if="newConsult.type === 0 && newConsult.status === 1" style="margin: 0 24px">
          <div style="color: #666666; font-size: 16px; margin: 0 0 12px 0">成交项目</div>
          <van-field
            v-model="newConsult.item"
            autosize
            style="background-color: #f5f5f5; border-radius: 12px"
            placeholder="请输入"></van-field>
          <div style="color: #666666; font-size: 16px; margin: 12px 0 12px 0">金额</div>
          <van-field
            v-model="newConsult.money"
            autosize
            type="number"
            style="background-color: #f5f5f5; border-radius: 12px"
            placeholder="请输入"></van-field>
        </div>
        <div style="display: flex; align-items: center; justify-content: center; margin-top: 24px">
          <van-button v-if="isSubmiting" loading type="info" loading-text="提交中..."></van-button>
          <van-button
            v-else
            round
            block
            type="info"
            plain
            style="width: 80%; height: 40px; background-color: #e5f0ff"
            @click="submitRecord">
            确认添加
          </van-button>
        </div>
      </div>
      <!--音频事件-->
      <div v-else-if="recordCard.cur === recordCard.audio" style="width: 100%; text-align: center">
        <div>
          <audio ref="audioPlayer" :src="recording" controls></audio>
        </div>
        <div style="padding: 10px 10px">
          <van-button
            style="width: 200px"
            type="primary"
            @touchstart.native.prevent="tchSpeak"
            @touchend.native.prevent="tchEnd">
            按住 说话
          </van-button>
          <van-button style="width: 100px" type="info" :disabled="!audioReady" @click="submitAudioRecord">
            提交音频
          </van-button>
        </div>
      </div>
      <!--图片事件-->
      <div v-else style="width: 100%; text-align: center">
        <div>
          <van-uploader
            v-model="recordPicList"
            preview-size="200"
            :max-count="1"
            style="margin: 0"
            :before-read="file => handleFileBeforeUpload(file, undefined)"
            :after-read="file => afterReadRecordPic(file, undefined)"></van-uploader>
        </div>
        <div>
          <van-button type="info" :disabled="!picReadyName" @click="submitPicRecord">提交图片</van-button>
        </div>
      </div>
    </van-popup>

    <!-- 面部标签 -->
    <van-popup
      v-model="popFt"
      closeable
      close-icon="close"
      position="top"
      :overlay="true"
      :lock-scroll="false"
      :style="{ height: '100%', width: '100%' }">
      <clerk-facial ref="refClerkFacial"></clerk-facial>
      <div
        style="
          position: fixed;
          background-color: #fff;
          width: 100%;
          height: 23%;
          left: 0;
          bottom: 0;
          border-radius: 24px 24px 0 0;
          padding: 16px;
        ">
        <div style="display: flex; width: 100%; justify-content: center; flex-direction: column; align-items: center">
          <div style="z-index: 2; text-align: center; color: #3387ff; font-size: 16px; font-weight: 600">面部标记</div>
          <div
            style="
              z-index: 1;
              width: 60px;
              height: 6px;
              background-image: linear-gradient(to right, #237eff, #d4e4fa);
              margin-top: -4px;
              border-radius: 8px;
            "></div>
        </div>
        <div style="background-color: #f5f5f5; padding: 1px 16px; border-radius: 12px; margin-top: 10px">
          <p v-if="pftTag !== ''">{{ pftTag }}</p>
          <p>{{ pftProposal }}</p>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
import Recorder from 'recorder-core';
// 引入mp3格式支持文件；如果需要多个格式支持，把这些格式的编码引擎js文件放到后面统统引入进来即可
import 'recorder-core/src/engine/mp3';
import 'recorder-core/src/engine/mp3-engine';
// 引入后端 API
import * as apiSts from '@/api/_com_';
import { closeOrderRecord, replyOrderRecord } from '@/api/record';
import { uploadCom } from '@/api/txs';
import { addDeal, addRecord, addRecordAudio, getRecordsByCid } from '@/api/ym';
// 引入自定义组件
import CommonBack from '@/components/back/index.vue';
import WebConst from '@/utils/const/web-const';
import RecordType from '@/utils/enum/record-type';
import Facial from '@/views/branch/clerks/Facial.vue';
// 引入第三方组件
import Compressor from 'compressorjs';
import {
  Notify,
  Button as VanButton,
  Field as VanField,
  Popup as VanPopup,
  Radio as VanRadio,
  RadioGroup as VanRadioGroup,
  Tabbar as VanTabbar,
  Uploader as VanUploader,
} from 'vant';
import 'vant/lib/button/style';
import 'vant/lib/field/style';
import 'vant/lib/popup/style';
import 'vant/lib/radio-group/style';
import 'vant/lib/radio/style';
import 'vant/lib/tabbar/style';
import 'vant/lib/uploader/style';
import { mapGetters } from 'vuex';

export default {
  name: 'Timeline',
  components: {
    VanButton,
    VanField,
    VanPopup,
    VanRadio,
    VanRadioGroup,
    VanTabbar,
    VanUploader,
    ['common-back']: CommonBack,
    ['clerk-facial']: Facial,
  },
  data() {
    return {
      recordCard: { cur: 1, normal: 1, pic: 2, audio: 3 },
      keyForTimeline: 0,
      lstRecord: [], // 时间线记录
      lstdeal: [], // lstRecord中的成交记录
      parentObj: undefined, // 父页面的顾客对象(修改需谨慎)
      consumerObj: {}, // 顾客对象
      RecordType: RecordType,
      newConsultDefault: {
        scene: '',
        status: 0,
        money: 0,
        content: '',
        trust: '',
        item: '',
        type: RecordType.CUSTOMER_RELATIONSHIP.id,
      },
      newConsult: {
        scene: '',
        status: 0,
        money: 0,
        content: '',
        trust: '',
        item: '',
        type: RecordType.CUSTOMER_RELATIONSHIP.id,
      },
      rec: null, // 录制对象
      audioReady: false, // 录音准备就绪
      popRecord: false, // 录音弹窗
      recording: '', // 录音文件
      recordPicList: [], // 图片文件
      picReadyName: false, // 图片准备就绪
      popFt: false, // 面部标签弹窗
      pftTag: '',
      pftProposal: '',
      audioBlob: null, // 录音文件
      isSubmiting: false, // 是否正在提交
    };
  },
  computed: {
    ...mapGetters(['name', 'id', 'deptId', 'openId']),
  },
  methods: {
    fltRecType(type) {
      const tmp = RecordType.getById(type);
      if (!tmp) {
        return '未知';
      }
      return tmp.name;
    },
    fltRecTypeColor(type) {
      switch (type) {
        case RecordType.CONSULTATION.id:
        case RecordType.FACIAL.id:
          return '#FF7510';
        case RecordType.FOLLOW_UP.id:
          return '#EFAC00';
        case RecordType.EMPOWERMENT.id:
          return '#00A61B';
        case RecordType.CUSTOMER_RELATIONSHIP.id:
          return '#1073FF';
        case RecordType.APPLY_ORDER.id:
          return 'red';
      }
    },
    fltRecTypeBgColor(type) {
      switch (type) {
        case RecordType.CONSULTATION.id:
        case RecordType.FACIAL.id:
          return '#FFECDE';
        case RecordType.FOLLOW_UP.id:
          return '#FFFADE';
        case RecordType.EMPOWERMENT.id:
          return '#E3F6E7';
        case RecordType.CUSTOMER_RELATIONSHIP.id:
          return '#DEECFF';
      }
    },
    handleClosePage: async function () {
      this.$emit('closed', 'click');
    },
    calSourceUrl: function (name) {
      return WebConst.getClerkImageUriByName(name);
    },
    loadRecord: async function (consumerObj) {
      this.popFt = false;
      this.popRecord = false;
      this.parentObj = consumerObj;
      this.consumerObj = Object.assign({}, consumerObj);
      this.newConsult = Object.assign({}, this.newConsultDefault);
      await this.goLoadRecord(this.consumerObj.id);
    },
    goLoadRecord: async function (cid) {
      this.lstRecord.splice(0, this.lstRecord.length);
      this.lstdeal.splice(0, this.lstdeal.length);
      const errAlertMsg = '获取记录失败';
      getRecordsByCid(cid)
        .then(res => {
          if (res.data.status !== apiSts.ResponseOK) {
            if (res.data.message) {
              Notify({ type: 'danger', message: res.data.message });
            } else {
              Notify({ type: 'danger', message: errAlertMsg });
            }
            return;
          }
          const ret = res.data.data;
          if (ret && ret.length > 0) {
            this.lstRecord = ret;
            this.lstdeal = this.lstRecord.filter(d => d.status === 1 && d.money > 0);
          }
          this.keyForTimeline += 1;
        })
        .catch(err => {
          console.log('goLoadRecord', err);
          Notify({ type: 'danger', message: errAlertMsg });
        });
    },
    replyOrder: async function () {
      if (this.newConsult.content) {
        this.newConsult.content = this.newConsult.content.trim();
      }
      if (!this.newConsult.content) {
        Notify({ type: 'danger', message: '会诊回复内容不能为空' });
        return;
      }
      const params = {};
      params.cid = this.consumerObj.id;
      params.rid = this.consumerObj.coachOrderId > 0 ? this.consumerObj.coachOrderId : null;
      params.reply = this.newConsult.content;
      const errAlertMsg = '回复会诊失败';
      await replyOrderRecord(params)
        .then(res => {
          if (res.data.status !== apiSts.ResponseOK) {
            if (res.data.message) {
              Notify({ type: 'danger', message: res.data.message });
            } else {
              Notify({ type: 'danger', message: errAlertMsg });
            }
            return;
          }
          this.popRecord = false;
          this.newConsult.content = '';
          this.goLoadRecord(this.consumerObj.id);
          Notify({ type: 'success', message: '提交成功' });
        })
        .catch(err => {
          console.error(err);
          Notify({ type: 'danger', message: errAlertMsg });
        });
    },
    goCloseOrder: async function () {
      const params = {};
      params.cid = this.consumerObj.id;
      params.rid = this.consumerObj.coachOrderId > 0 ? this.consumerObj.coachOrderId : null;
      const errAlertMsg = '关闭会诊失败';
      await closeOrderRecord(params)
        .then(res => {
          if (res.data.status !== apiSts.ResponseOK) {
            if (res.data.message) {
              Notify({ type: 'danger', message: res.data.message });
            } else {
              Notify({ type: 'danger', message: errAlertMsg });
            }
            return;
          }
          this.popRecord = false;
          this.consumerObj.coachOrderId = -1;
          this.parentObj.coachOrderId = -1;
          this.goLoadRecord(this.consumerObj.id);
          Notify({ type: 'success', message: '提交成功' });
        })
        .catch(err => {
          console.error(err);
          Notify({ type: 'danger', message: errAlertMsg });
        });
    },
    iniRecord() {
      this.newConsult = this.$options.data().newConsult;
      this.newConsult.cid = this.consumerObj.id;
      this.newConsult.recorder = this.name;
      this.recordCard.cur = this.recordCard.normal;
      this.rec = Recorder({
        type: 'mp3', // 录音格式，可以换成wav等其他格式
        sampleRate: 16000, // 录音的采样率，越大细节越丰富越细腻
        bitRate: 16, // 录音的比特率，越大音质越好
        onProcess: (buffers, powerLevel, duration, bufferSampleRate) => {
          // console.log(buffers);
          // 录音实时回调，大约1秒调用12次本回调
          // 可实时绘制波形，实时上传（发送）数据
          // if (wave) {
          //   wave.input(buffers[buffers.length - 1], powerLevel, bufferSampleRate);
          // }
        },
      });
      this.rec.open(
        () => {
          // if (recwave.value) {
          //   //创建音频可视化图形绘制对象
          //   wave = Recorder.WaveView({ elem: recwave.value });
          // }
        },
        (msg, isUserNotAllow) => {
          // 用户拒绝了录音权限，或者浏览器不支持录音
          console.log((isUserNotAllow ? 'UserNotAllow，' : '') + '无法录音:' + msg);
        }
      );
      this.audioReady = false;
      this.popRecord = true;
    },
    popFaceTag: async function (val) {
      // this.facePic = this.consumerObj.pic[0] ? this.consumerObj.pic[0].url : ''
      if (val.type === 4) {
        this.pftTag = val.item;
        this.pftProposal = val.content;
        this.popFt = true;
        await this.$nextTick();
        this.$refs.refClerkFacial.showFacialModel(val.trust);
      }
    },
    tchSpeak() {
      this.audioReady = false;
      if (this.rec != null) {
        // alert('当前浏览器不支持录音功能！');
        this.rec.start();
      }
    },
    tchEnd() {
      if (this.rec != null) {
        this.rec.stop(
          (blob, duration) => {
            this.recording = URL.createObjectURL(blob);
            this.audioBlob = blob;
            this.audioReady = true;
            // this.rec.close(); //关闭录音，释放录音资源，当然可以不释放，后面可以连续调用start
            // this.rec = null;
          },
          err => {
            console.error('结束录音出错：' + err);
            this.rec.close(); // 关闭录音，释放录音资源，当然可以不释放，后面可以连续调用start
            this.rec = null;
          }
        );
      }
    },
    closeRecord() {
      this.recordPicList.splice(0, this.recordPicList.length);
      this.recording = '';
      this.rec.close();
      this.rec = null;
      this.popRecord = false;
    },
    handleFileBeforeUpload(file) {
      const allowFileTypes = ['jpg', 'jpeg', 'png'];
      const fileType = file.name.split('.').pop().toLowerCase();
      if (allowFileTypes.indexOf(fileType) === -1) {
        Notify({ type: 'danger', message: '只能上传 jpg,jpeg,png 图片!' });
        return false;
      }
      if (file.size > 1024 * 500) {
        return new Promise(resolve => {
          new Compressor(file, {
            quality: 0.8,
            maxWidth: 1000,
            maxHeight: 1000,
            convertSize: 500000,
            success(result) {
              const file1 = new File([result], file.name, { type: file.type });
              resolve(file1);
            },
            error(err) {
              console.log(err.message);
            },
          });
        });
      }
      return true;
    },
    afterReadRecordPic: async function (options) {
      this.picReadyName = false;
      const dataInfo = new FormData();
      dataInfo.append('file', options.file);
      const errAlertMsg = '主图上传失败';
      options.status = 'uploading';
      options.message = '上传中...';
      uploadCom(dataInfo)
        .then(res => {
          if (res.data.status !== apiSts.ResponseOK) {
            if (res.data.message) {
              Notify({ type: 'danger', message: res.data.message });
            } else {
              Notify({ type: 'danger', message: errAlertMsg });
            }
            return;
          }
          const ret = res.data.data;
          options.status = 'done';
          options.url = ret;
          this.picReadyName = WebConst.getImageFilename(ret);
        })
        .catch(err => {
          console.log('handleImgMainUpload', err);
          options.status = 'failed';
          options.message = '上传失败';
        });
    },
    submitAudioRecord: async function () {
      const dataInfo = new FormData();
      dataInfo.append('file', this.audioBlob, Math.floor(Math.random() * 1000) + '.mp3');
      dataInfo.append('cid', this.newConsult.cid);
      dataInfo.append('recorder', this.newConsult.recorder);
      await addRecordAudio(dataInfo);
      this.audioReady = false;
      this.closeRecord();
      this.goLoadRecord(this.consumerObj.id);
      Notify({ type: 'success', message: '提交成功' });
    },
    submitPicRecord: async function () {
      await addRecord({
        cid: this.newConsult.cid,
        recorder: this.newConsult.recorder,
        type: RecordType.IMAGE.id,
        url: this.picReadyName,
      });
      this.picReadyName = false;
      this.closeRecord();
      this.goLoadRecord(this.consumerObj.id);
      Notify({ type: 'success', message: '提交成功' });
    },
    /**
     * 提交记录
     * <p>
     * 1. 如果是咨询记录，判断是否成交，如果成交则记录成交, 后台更新顾客等级;
     * 2. 否则, 直接记录时间线
     */
    submitRecord: async function () {
      const isDeal = this.newConsult.type === RecordType.CONSULTATION.id && this.newConsult.status === 1;
      if (isDeal && this.newConsult.money <= 0) {
        Notify({ type: 'danger', message: '成交金额必须大于0' });
        return;
      }
      this.newConsult.item = this.newConsult.item.trim();
      if (isDeal && this.newConsult.item === '') {
        Notify({ type: 'danger', message: '成交项目不能为空' });
        return;
      }
      if (this.newConsult.content) {
        this.newConsult.content = this.newConsult.content.trim();
      }
      if (this.newConsult.type == RecordType.APPLY_ORDER.id && !this.newConsult.content) {
        Notify({ type: 'danger', message: '提会诊需要简单描述下需求, 例如: 需要什么协助' });
        return;
      }
      if (this.newConsult.type == RecordType.APPLY_ORDER.id && this.consumerObj.coachOrderId > 0) {
        this.replyOrder();
        return;
      }
      // 如是成交记录, 则记录成交
      this.isSubmiting = true;
      if (isDeal && !(await this.submitDeal())) {
        this.isSubmiting = false;
        return;
      }
      // 记录时间线
      const errAlertMsg = '提交失败';
      if (isDeal || this.newConsult.content) {
        await addRecord(this.newConsult)
          .then(res => {
            if (res.data.status !== apiSts.ResponseOK) {
              if (res.data.message) {
                Notify({ type: 'danger', message: res.data.message });
              } else {
                Notify({ type: 'danger', message: errAlertMsg });
              }
              return;
            }
            const ret = res.data.data;
            if (ret) {
              ret.createTime = new Date().toLocaleString();
              this.lstRecord.splice(0, 0, ret);
              if (this.newConsult.type == RecordType.APPLY_ORDER.id && !(this.consumerObj.coachOrderId > 0)) {
                this.consumerObj.coachOrderId = ret.id;
                this.parentObj.coachOrderId = ret.id;
              }
            }
            Notify({ type: 'success', message: '提交成功' });
          })
          .catch(err => {
            console.log('submitRecord', err);
            Notify({ type: 'danger', message: errAlertMsg });
          })
          .finally(() => {
            this.isSubmiting = false;
          });
      }
      this.handleClosePage();
    },
    submitDeal: async function () {
      let ok = false;
      const errAlertMsg = '提交失败';
      await addDeal({
        cid: this.consumerObj.id,
        cname: this.consumerObj.cname,
        kid: this.id,
        kname: this.name,
        sid: this.openId,
        sname: this.consumerObj.sname,
        item: this.newConsult.item,
        money: this.newConsult.money,
      })
        .then(res => {
          if (res.data.status !== apiSts.ResponseOK) {
            if (res.data.message) {
              Notify({ type: 'danger', message: res.data.message });
            } else {
              Notify({ type: 'danger', message: errAlertMsg });
            }
            return;
          }
          this.lstdeal.unshift({
            item: this.newConsult.item,
            money: this.newConsult.money,
            createTime: new Date().toLocaleString().replaceAll('/', '-'),
          });
          ok = true;
        })
        .catch(err => {
          console.log('submitDeal', err);
          Notify({ type: 'danger', message: errAlertMsg });
        });
      return ok;
    },
  },
};
</script>

<style lang="scss" scoped>
.consultation {
  margin: 5px 0 0 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 2px;
}
</style>
